Skip to content

feat(#535): dsh phase 4 — split by destination (last overlay shrinks to loopback) - #544

Merged
ranxianglei merged 3 commits into
masterfrom
2026-09-05_dsh-phase4
Sep 6, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-09-05_dsh-phase4

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Phase 4 of #535 (the last remaining issue item): dsh no longer force-routes all upstreams through the /bili/ settings rewrite. Discovery splits settings.yaml endpoints by destination, matching dsh's actual fetch behavior:

upstream mechanism
loopback (http or https) /bili/ rewrite via persistent DSH_HOME overlay (~/.dsh-bili) — the documented exception: dsh's fetch stack bypasses proxy envs for loopback targets unconditionally (LOOPBACK_NO_PROXY, "the bypass is not optional")
non-loopback https CONNECT + cert MITM — host added to the MITM whitelist, child gets HTTPS_PROXY + SSL_CERT_FILE → combined-ca.pem (it replaces dsh's trust store, so system roots must be bundled — same pattern as codex)
non-loopback plain-http absolute-form forward-proxy requests via HTTP_PROXY (server support landed in #538)
built-in deepseek-official route unchanged: $DEEPSEEK_BASE_URL wrap

Behavioral parity: proxy envs are set only when something actually routes through them — a launch with no non-loopback custom providers produces the same child env as before. Inherited proxy vars are fully stripped from the child (same contract as hermes); dsh's loopback exclusion comes from its built-in policy, so no NO_PROXY juggling is needed.

Docs (EN+ZH)

  • README: new “Injection priority — no files unless unavoidable” section next to Two compression modes (env > CLI/extension API > generated files; bili never owns user data; legacy overlays left in place, never merged back) + updated dsh one-liner.
  • CONFIGURATION: redirect table, discovery table and the generated-files section updated for the dsh split — plus the pi/omp/hermes rows and bullets that phases 1–2 left stale (they still described the removed PI_CODING_AGENT_DIR / HERMES_HOME overlays). All phases are merged now, so the docs finally match the code.

Pre-flight

  • npm run typecheck clean
  • npm test: 1028/1029 pass — sole failure is the sandbox-only resolveClientCommand: codex/claude resolve to themselves (/usr/bin/codex exists in this sandbox; fails on pristine master too)
  • npm run build OK

New tests: isLoopbackHost units; dsh discovery split (loopback→rewrite, https→whitelist, http→env-routes, wrapped-value unwrap, dedupe, malformed skip); runLaunch dsh combined fixture (proxy envs + NO_PROXY strip + MITM-domain capture + overlay rewrites ONLY the loopback line + real home byte-identical); runLaunch dsh no-loopback fixture (no DSH_HOME, patch-only -bili dir).

Notes

  • This is the final phase of 注入零文件化:废除 overlay/临时目录机制(#531 设计返工) #535. After merge, the only generated-file mechanisms left in the launcher are opencode's temp opencode.json (removed on exit) and the dsh loopback overlay — both documented as last-resort exceptions. Full refreshOverlayHome abolition can be revisited once dsh gains a settings-path env or an upstream loopback opt-out.
  • No version bump (release flow territory).

ework-agent added 2 commits September 5, 2026 10:46
…opback

dsh's fetch stack honors proxy envs except an unconditional loopback
bypass (LOOPBACK_NO_PROXY), so discovery now splits settings.yaml
endpoints by destination: loopback (http OR https) keeps the /bili/
settings rewrite via the persistent DSH_HOME overlay (documented
exception); non-loopback https rides CONNECT + cert MITM (host added
to the whitelist); non-loopback plain-http rides absolute-form
forward-proxy requests via HTTP_PROXY. The child gets HTTPS_PROXY +
SSL_CERT_FILE (combined bundle — it replaces the trust store) only
when something actually routes through them, so no-custom-provider
launches behave exactly as before. Built-in deepseek route stays on
DEEPSEEK_BASE_URL. isLoopbackHost helper + tests; banner gains the
proxy-env route count.
README (EN+ZH): new 'Injection priority' section near the two
compression modes (env > CLI/extension API > generated files; bili
never owns user data; legacy overlays left unmigrated) and the dsh
one-liner. CONFIGURATION (EN+ZH): redirect table, discovery table and
the generated-files section updated for the dsh split, plus the pi/omp
and hermes rows/bullets that phases 1-2 left stale (they described the
removed PI_CODING_AGENT_DIR / HERMES_HOME overlays).
@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-05_dsh-phase4 (2c00632)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-544

Each push to this PR publishes a new version under the pr-544 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr544.tgz
npm install -g package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · qwen3.8-27b

[bot] 🏷 Reviewed PR #544 against master (1502287) — LGTM, verified, ready for merge (merge itself stays with you).

What I independently re-verified

Pre-flight (re-run on head a819ed8): npm run typecheck clean; npm test 1028/1029; npm run build OK. The sole failure (resolveClientCommand: codex/claude resolve to themselves) is environmental — I checked out pristine master in a separate worktree and it fails there too (launcher.test.ts 98/99 on master), so it's not a regression.

Code (src/launcher.ts):

  • Destination split in discoverRoutes is correct: loopback (http or https) → /bili/ rewrite keys; non-loopback https → MITM whitelist (deduped by lowercased hostname, /bili/-wrapped values unwrapped first); non-loopback plain-http → httpEnvRoutes`; malformed entries skipped; dedupe by real upstream preserved from before.
  • isLoopbackHost (localhost / LOCALHOST / ::1 / [::1] / 127.0.0.0/8) is a superset of dsh's exact-match bypass list (LOOPBACK_NO_POLICY = ['localhost','127.0.0.1','::1','[::1]'], policy.ts:33 per 注入零文件化:废除 overlay/临时目录机制(#531 设计返工) #535). That direction is safe: any endpoint dsh would bypass is also routed by bili via the rewrite path, so there is no silent-bypass direction. The only theoretical divergence (a host dsh treats as non-loopback that bili also sees as non-loopback) lands on proxy envs, which dsh honors — consistent.
  • Behavioral parity claim confirmed against master code: master's dsh branch did not strip inherited proxy vars either, and phase 4 only applies stripInheritedProxy when usesProxyEnv is true — so a launch with no non-loopback custom providers produces the identical child env as before.
  • prepareDshHome implementation is byte-for-byte unchanged (docstring only) — the overlay now just receives fewer lines to rewrite, which the combined fixture proves (overlayTxt contains the rewritten loopback line AND the untouched https://api.anthropic.com line; real home byte-identical).
  • Warning ladder correctly updated (loopback rewrite failure now says "loopback custom providers will NOT go through the proxy; other routes still do").

Server-side dependency: absolute-form forward-proxy handling is present in master from #538 (src/server.ts:294-311 — absolute-form request line treated like the /bili/ embedded form, full pipeline + #409 destination admission). The HTTP_PROXY route for plain-http non-loopback upstreams has its server half landed.

MITM wiring: routes.httpsDomains flows into the proxy spawn via domains = dedupeInOrder([...routes.httpsDomains, ...params.mitmDomains]) (src/launcher.ts:1710) → BILI_MITM_DOMAINS (:1518). The new runLaunch fixture captures the proxy-spawn env and asserts api.anthropic.com is in it — end-to-end wiring covered, not just discovery.

Tests (+129): match the description exactly — split matrix incl. wrapped-value unwrap/dedupe/malformed-skip, isLoopbackHost units (incl. 1270.0.0.1 negative), combined fixture (HTTPS_PROXY + combined-ca.pem, NO_PROXY stripped, HTTP_PROXY absent when unused, overlay rewrites ONLY the loopback line, profiles symlink, patch file + --patch splice), no-loopback fixture (inherited DSH_HOME passes through unchanged, -bili dir holds only .bili-acp.patch.yml).

Docs (EN+ZH): accurate and consistent with the code. The stale pi/omp rows (PI_CODING_AGENT_DIR) and hermes row (HERMES_HOME, "all upstreams /bili/") left over from phases 1–2 are fixed, the generated-files section is retitled to last-resort framing, and the new README "Injection priority" section sits next to Two compression modes as described. ZH mirrors EN without drift.

Non-blocking notes

  1. No real-machine dsh e2e was possible here (no dsh binary in this environment) — the change hinges on dsh honoring HTTPS_PROXY/HTTP_PROXY/SSL_CERT_FILE, which is source-verified (注入零文件化:废除 overlay/临时目录机制(#531 设计返工) #535 OP, deepseek-harness packages/util/http-proxy) but not runtime-exercised in CI. Suggested post-install smoke: one loopback upstream (overlay path), one remote https provider (MITM path), optionally one remote plain-http (absolute-form path).
  2. DEEPSEEK_BASE_URL wrap intentionally kept (per your floor-12 scoping); the whitelist alternative from the feat(#535): zero-file injection phases 2+3 — absolute-form forward proxy, hermes/dsh env routing #537 review (add api.deepseek.com instead of overriding user-set env) remains available as a follow-up if you ever want zero env override there.
  3. After merge, all 注入零文件化:废除 overlay/临时目录机制(#531 设计返工) #535 checklist items are landed — the umbrella issue can be closed whenever you're ready (the two documented exceptions — opencode temp config, dsh loopback overlay — are tracked in this PR's notes rather than open work items).

No version bump present, release-flow rules respected. Nothing here touches the request pipeline (server.ts/loop/adapters), so the codex E2E suite isn't triggered by this change.

… prefix

h.split('.')[0] === '127' also matched hostnames like 127.evil.com.
Tightened to /^127\.\d+\.\d+\.\d+$/ per review; regression cases
added (127.evil.com, 127.abc.def).
@ranxianglei
ranxianglei merged commit 95b1c08 into master Sep 6, 2026
6 checks passed
ranxianglei pushed a commit that referenced this pull request Sep 6, 2026
#553)

Semantic merge onto current master. The fork-predate relax walk (#544/
#575), wire overhead (#470), image floors (#488), side-request isolation
(#388) and pi host-usage (#590) all landed after this PR's fork point
(09ef208). Resolution:
- preflight.ts: char regime (unknownBaseline / estimateCoreMessagesUpper /
  char-based splitChunks + netting / fitsWindow) grafted onto the multi-
  range walk; the upper bound also carries the image+wire floors.
- server.ts: effectiveTokenCount feeds all three prepare branches; the
  trigger's tokenCount uses upper+floors only for anonymous zero-baseline
  sessions; unknown-baseline keeps the loop's fitsWindow judgment, known
  keeps master's rebuilt-payload re-estimate (#330).
- unknown-baseline + nothing-compressible fails fast (PR semantics);
  known-baseline falls through to preflightCompress so the #330 relax
  path still runs.
- Tests adapted to current master/kernel: fork conversation reshaped for
  the kernel's minPressureBenefit (5k) band and main-request shape
  (max_tokens>200) since #388 now routes the old shape to passthrough.
@ranxianglei
ranxianglei deleted the 2026-09-05_dsh-phase4 branch October 15, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant